﻿Imports System.Configuration

Namespace Configuration

    Public Class ContactElement
        Inherits ConfigurationElement

        '<Contact TYpe="Board" Name="" Email="" Phone="" />

        <ConfigurationProperty("Type", IsKey:=True, IsRequired:=True)> _
        Public Property Type() As String
            Get
                Return DirectCast(Me("Type"), String)
            End Get
            Set(ByVal value As String)
                Me("Type") = value
            End Set
        End Property

        <ConfigurationProperty("Name", IsRequired:=True)> _
        Public Property Name() As String
            Get
                Return DirectCast(Me("Name"), String)
            End Get
            Set(ByVal value As String)
                Me("Name") = value
            End Set
        End Property

        <ConfigurationProperty("Email", IsRequired:=True)> _
        Public Property Email() As String
            Get
                Return DirectCast(Me("Email"), String)
            End Get
            Set(ByVal value As String)
                Me("Email") = value
            End Set
        End Property

        <ConfigurationProperty("Phone", IsRequired:=False)> _
        Public Property Phone() As String
            Get
                Return DirectCast(Me("Phone"), String)
            End Get
            Set(ByVal value As String)
                Me("Phone") = value
            End Set
        End Property

    End Class

    <ConfigurationCollection(GetType(ContactElement))> _
    Public Class ContactCollection
        Inherits ConfigurationElementCollection

        Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement
            Return New ContactElement()
        End Function

        Protected Overloads Overrides Function GetElementKey(ByVal element As ConfigurationElement) As Object
            Return DirectCast((element), ContactElement).Type
        End Function

        Default Public Shadows ReadOnly Property Item(ByVal idx As Integer) As ContactElement
            Get
                Return DirectCast(BaseGet(idx), ContactElement)
            End Get
        End Property

    End Class

End Namespace
